<!--

function aL(){
	var a=null;
	
	if(window.ActiveXObject){
		a=new ActiveXObject("Msxml2.XMLHTTP");
		if(!a){
			a=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}else if(window.XMLHttpRequest){	
		a= new XMLHttpRequest();
	}
	return a
}

function getAdminEdit(span_id, type, id){		
	var element = document.getElementById(span_id);
	element.innerHTML = '<table width="100%" border="0" cellspacing="1" cellpadding="1" class="tb"><tr><td colspan=3 align="center">Waiting...</td><tr>';

	var ab=aL();	
	var a='../admin/getdo.php?type=' + type + '&span_id=' + span_id + '&id=' + id;
	ab.open("GET",a);

	ab.onreadystatechange=function(){
		if (ab.readyState == 4 && ab.status == 200) {   
		    if (ab.responseText == "" || ab.responseText == null) {
		        element.innerHTML = '<span id='+span_id+'><table width="100%" border="0" cellspacing="1" cellpadding="1" class="tb"><tr><td colspan=3 align="center">Timeout.Please <a href="javascript:getCategoryEdit(\''+span_id+'\',\''+type+'\', \''+id+'\')">click here</a> to retry</td></tr></table></span>';
		    } else {
				//alert(ab.responseText);
			    element.innerHTML = ab.responseText;
		    }
		}		
	}
	ab.send(null);	
}

//Ʒб仯
function CategoryChange(fid,level,tdID){
    //¼˵
    $("#"+tdID).find("select").each(function(i){
            if(i>level)
            {
                $(this).remove();
            }
    });	
    
    //õǰ𼶱
    $("#hdLevel").val(level);
    
    //ѡ,¼
    if(fid==0)
    {
        return;
    }
    
    //AJAX
    $.ajax({
        type: 'POST',
        url: 'getdo.php',
        data:{id:fid,type:39},
        dataType:"json",
        beforeSend: function() {
            ClearMsg("spanMsg");//Ϣ
            $("#"+tdID).append("<span id=\"spanMsg\">Loading...</span>");//ʾϢ
        },
        success: function(json) {            
            ClearMsg("spanMsg");//Ϣ
            if(json!="")
            {
                var mySelect = document.getElementById("Parent"+(level+1));
                if(mySelect == null || mySelect =="undefine")
                    mySelect = document.createElement("select"); 
                else 
                    mySelect.options.length=0;
                        
                $(mySelect).attr({id:"Parent"+(level+1),name:"Parent"+(level+1),"class":"select"});
                $(mySelect).change(function(){
                    CategoryChange($(this).val(),level+1,tdID);
                });
                
                mySelect.options.add(new Option("--none--","0"));
                $(json).each(function(i){
                    mySelect.options.add(new Option($(this)[0].name,$(this)[0].id));
                });
                
                $("#"+tdID).append(mySelect);            
            }

        },
        error: function(o,err) {
            alert("Loading product category error:"+err);
        }
    });
}
function ClearMsg(id)
{
    if($("#"+id)!= null || $("#"+id)!="undefine")
    {
        $("#"+id).empty().remove();
    }
}

function on_ax_submit(span_id, type, set_value) {
    getAdminEdit(span_id, type, set_value);
}

function showMsg(span_id, msg) {
    var element = document.getElementById(span_id);
	element.innerHTML = '<span id="'+ span_id +'" class="js_msg">'+ msg +'</span>';
}

function adminEditCancel(span_id) {
    var element = document.getElementById(span_id);
	element.innerHTML = '<span id="'+ span_id +'"></span>';
}

function adminEditPassCancel(span_id, id, msg) {
    var element = document.getElementById(span_id);
	element.innerHTML = '<span id="'+ span_id +'"><div onclick="getAdminEdit(\''+ span_id +'\', \'31\', \''+ id +'\')">'+msg+'&nbsp;&nbsp;&nbsp;&nbsp;</div></span>';
}

function validate_add(form, input_value) {
	if(form.name.value == input_value) {
		showMsg('msg_area', 'Please enter value.');
		form.name.focus();
		return false;
		exit();
	}
	
	form.submit();
}

function validate_search(form, input_value) {
	
	if(form.key.value == input_value) {
		//if(form.key.value == "") {
		showMsg('msg_area', 'Please enter value.');
		form.key.focus();
		return false;
		exit();
	}
	
	form.submit();
}

function validate_searchUserList(form, input_value) {
	
	if(form.key.value =="")
	{		   
		showMsg('msg_area', 'Please enter value.');
		form.key.focus();
		return false;
		exit();
	}
	form.submit();
}

function isDigit(s) 
{ 
	var patrn=/^[0-9]{0,8}$/; 
	if (!patrn.exec(s)) return false 
	return true 
} 

function isUrl(s) 
{ 
	if (s.indexOf('http://', 0) == -1) return false 
	return true 
} 

function isEmail(s) 
{ 
	var patrn=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/; 
	if (!patrn.exec(s)) return false 
	return true
} 

// ƶı<tr>ɫ
var old_bc = "";
function trOn(t) {
	old_bc = t.bgColor;
	t.bgColor = "#B68F2E";
}
function trOut(t) {
	t.bgColor = old_bc;
}


// Checkbox Switcher
// return checked number and checked value string(like 3,5,9,11)
// Example: <input type=button value="switch" onClick="switchCheckbox('',form,form.C1)">
// Example: <input type=button value="switch" onClick="switchCheckbox('',"C1[]")">
// Write by Macro Zeng macroz@gmail.com http://www.dyddy.com
function switchCheckbox(type,f,o)	{
	var checked_ary = Array(0,'');
	if ( typeof(o) == "object" )	{
		switch (type) {
			case 'all' : 
				for ( i=0; i<o.length; i++ )	{
					o[i].checked = true;
				}
				break;
			case 'empty' : 
				for ( i=0; i<o.length; i++ )	{
					o[i].checked = false;
				}
				break;
			case 'switch' : 
				for ( i=0; i<o.length; i++ )	{
					o[i].checked = !o[i].checked;
				}
				break;
		}
		for ( i=0; i<o.length; i++ )	{
			if ( o[i].checked == true )	{
				checked_ary[0]++;
				checked_ary[1] += f.elements[i].value + ',';
			}
		}
	} else {
		switch (type) {
			case 'all' : 
				for ( i=0; i<f.elements.length; i++ )	{
					if ( f.elements[i].type == 'checkbox' && f.elements[i].name.indexOf(o) != -1)	{
						f.elements[i].checked = true;
					}
				}
				break;
			case 'empty' : 
				for ( i=0; i<f.elements.length; i++ )	{
					if ( f.elements[i].type == 'checkbox' && f.elements[i].name.indexOf(o) != -1)	{
						f.elements[i].checked = false;
					}
				}
				break;
			case 'switch' : 
				for ( i=0; i<f.elements.length; i++ )	{
					if ( f.elements[i].type == 'checkbox' && f.elements[i].name.indexOf(o) != -1 )	{
						f.elements[i].checked = !f.elements[i].checked;
					}
				}
				break;
		}
		for ( i=0; i<f.elements.length; i++ )	{
			if ( f.elements[i].type == 'checkbox' && f.elements[i].name.indexOf(o) != -1 && f.elements[i].checked == true )	{
				checked_ary[0]++;
				checked_ary[1] += f.elements[i].value + ',';
			}
		}
	}
	if ( checked_ary[1] != '' )	{
		checked_ary[1] = checked_ary[1].substr(0, checked_ary[1].length-1);
	}
	return checked_ary;
}
-->